<?php

    abstract class PhpDbAbstractStatement // Classe specifiant les methodes a implementer dans une souscouche
    {
        const EXCEPTION_QUERY = 1;
        const EXCEPTION_BIND = 2;

        public $host = '';
        public $statement = '';
        public $params = '';
        public $cursor = NULL;
        public $queryString = '';
        public $attributes = array();

        # constructeur
        public function __construct ( $host, $statement )
        {
            $this->host = $host;
            $this->statement = $statement;
        }
        public function exception($type,$message,$noadd=false)
        {
            if($noadd)
                $type = 'NONE';
            switch($type)
            {
                case self::EXCEPTION_QUERY:
                case self::EXCEPTION_BIND:
                    $params = array();
                    foreach($this->params as $name=>$data)
                        $params[$name] = print_r($data['value'],true).' ('.$data['mode'].'-'.$this->getTypeTexte($data['type']).')';
                    throw new Exception($message."\n\n".$this->statement."\n\n".print_r($params,true));
                default:
                    throw new Exception($message);
            }
        }
        public function getTypeTexte($type)
        {
            switch($type)
            {
                case PDO::PARAM_BOOL: return 'BOOL';
                case PDO::PARAM_NULL: return 'NULL';
                case PDO::PARAM_INT: return 'INT';
                case PDO::PARAM_STR: return 'STR';
                case PDO::PARAM_LOB: return 'LOB';
                case PDO::PARAM_STMT: return 'STMT';
                case PDO::PARAM_INPUT_OUTPUT: return 'INOUT';
            }
            return '??';
        }

        # methodes PhpDb

        # methodes PDO
        /*bool*/ public abstract function bindColumn ( $column , &$param , $type = NULL , $maxlen = NULL , $driverdata = NULL );
        /*bool*/ public abstract function bindParam ( $parameter , &$variable, $data_type = PhpDb::PARAM_STR , $length = NULL , $driver_options = NULL );
        /*bool*/ public abstract function bindValue ( $parameter , $value , $data_type = PhpDb::PARAM_STR );
        /*bool*/ public abstract function closeCursor ( );
        /*int*/ public abstract function columnCount ( );
        /*bool*/ public abstract function debugDumpParams ( );
        /*string*/ public abstract function errorCode ( );
        /*array*/ public abstract function errorInfo ( );
        /*bool*/ public abstract function execute ( $input_parameters = array() );
        /*mixed*/ public abstract function fetch ( $fetch_style = PhpDb::FETCH_BOTH , $cursor_orientation = PhpDb::FETCH_ORI_NEXT , $cursor_offset = 0 );
        /*array*/ public abstract function fetchAll ( $fetch_style = PhpDb::FETCH_BOTH , $column_index = 0 , $ctor_args = array() );
        /*string*/ public abstract function fetchColumn ( $column_number = 0 );
        /*mixed*/ public abstract function fetchObject ( $class_name = "stdClass", $ctor_args = NULL );
        /*mixed*/ public abstract function getAttribute ( $attribute );
        /*array*/ public abstract function getColumnMeta ( $column );
        /*bool*/ public abstract function nextRowset ( );
        /*int*/ public abstract function rowCount ( );
        /*bool*/ public abstract function setAttribute ( $attribute , $value );
        /*bool*/ public abstract function setFetchMode ( $mode , $params=NULL );
    }

?>
